package com.asset.dispoal.batchEvidenceTypeMapper.service.commom;

import com.asset.dispoal.batchEvidenceTypeMapper.domain.db.entity.SysBatchEvidenceTypeMapper;
import com.asset.dispoal.batchEvidenceTypeMapper.domain.db.mapper.SysBatchEvidenceTypeMapperMapper;
import com.asset.dispoal.batchEvidenceTypeMapper.dto.SysBatchEvidenceTypeMapperRequest;
import com.asset.dispoal.batchEvidenceTypeMapper.dto.SysBatchEvidenceTypeMapperResponse;
import com.asset.dispoal.batchEvidenceTypeMapper.service.converter.SysBatchEvidenceTypeMapperConverter;
import com.asset.dispoal.commom.page.PagingQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

/**
 * @author qr
 * @date 2022/3/25$
 */
@Component
public class SysBatchEvidenceTypeMapperQueryPageCommand implements BaseCommand<SysBatchEvidenceTypeMapperRequest, Result<PageVO<SysBatchEvidenceTypeMapperResponse>>> {


    @Autowired
    SysBatchEvidenceTypeMapperMapper sysBatchEvidenceTypeMapperMapper;

    @Override
    public Result<PageVO<SysBatchEvidenceTypeMapperResponse>> execute(SysBatchEvidenceTypeMapperRequest request) {
        SysBatchEvidenceTypeMapper sysBatchEvidenceTypeMapper = SysBatchEvidenceTypeMapperConverter.INSTANCE.resToDo(request);
        int count = sysBatchEvidenceTypeMapperMapper.count(sysBatchEvidenceTypeMapper);
        Page<SysBatchEvidenceTypeMapper> page = PagingQuery.getPage(count, sysBatchEvidenceTypeMapper);
        PageVO<SysBatchEvidenceTypeMapperResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            List<SysBatchEvidenceTypeMapper> mapperList = sysBatchEvidenceTypeMapperMapper.page(page);
            List<SysBatchEvidenceTypeMapperResponse> sysBatchEvidenceTypeMapperResponses = SysBatchEvidenceTypeMapperConverter.INSTANCE.dosToRes(mapperList);
            pageVO.setResult(sysBatchEvidenceTypeMapperResponses);
        }
        return Result.ok(pageVO);
    }
}
